<?php
/**
 * 用户管理控制器
 */
namespace Home\Controller;
use Think\Controller;
class LbglController extends AController {

    public function JsonDataProcessing($json){
        $json = str_replace("&quot;","\"",$json);
        $json = json_decode($json,true);
        $arr['text'] = $json['text'];
        if($json['img']){
            $images = explode(',',$json['img']);
            for ($i=0; $i < count($images); $i++) {
                $arr['img'][$i]='/infoRecordBackend/Uploads/'.$images[$i];
            }
        }
        return $arr;
    }

    //获取产品列表信息
    public function info(){
        //判断用户是否登录
        $user = $_SESSION['user'];
        if(!$user){
            $this->error('请先登陆',U('Login/login'));
        }
        $userList = M('user')->order('id desc')->select();
        $key_word = I('get.key_word');

        $p = I('p');
        if(!$p){
            $p = 1;
        }
        $num = 10;

        if($key_word){
            $word='%'.$key_word.'%';
            $where['id']=array('eq',$key_word);
            $where['name']=array('like',$word);
            $where['user']=array('like',$word);
            $where['tel']=array('like',$word);
            $where['IDcard']=array('eq',$key_word);
            $where['_logic'] = 'OR';
            $list = M('info')->where($where)->order('time desc')->page($p.','.$num)->select();
            //print_r($list);
            $count= M('info')->where($where)->count();
            // echo  M('user')->getLastSql();
            //echo $count;
            //$this->ajaxReturn($list);
        }else{
            //查询用户
            $list = M('info')->order('time desc')->page($p.','.$num)->select();
            $count      = M('info')->count();// 查询满足要求的总记录数
        }
        //查询用户
        //$list = M('info')->order('time desc')->select();
        foreach ($list as $key=>$val){
                $arrHouse = $this->JsonDataProcessing($list[$key]['house']);
                $list[$key]['houseText']=$arrHouse['text'];
                $list[$key]['houseImg']=$arrHouse['img'];

                $arrCar = $this->JsonDataProcessing($list[$key]['car']);
                $list[$key]['carText']=$arrCar['text'];
                $list[$key]['carImg']=$arrCar['img'];

                $arrPolicy = $this->JsonDataProcessing($list[$key]['fund']);
                $list[$key]['policyText']=$arrPolicy['text'];
                $list[$key]['policyImg']=$arrPolicy['img'];

                $arrFund = $this->JsonDataProcessing($list[$key]['fund']);
                $list[$key]['fundText']=$arrFund['text'];
                $list[$key]['fundImg']=$arrFund['img'];

                $arrSecurity = $this->JsonDataProcessing($list[$key]['social_security']);
                $list[$key]['securityText']=$arrSecurity['text'];
                $list[$key]['securityImg']=$arrSecurity['img'];

                $arrLicense = $this->JsonDataProcessing($list[$key]['license']);
                $list[$key]['licenseText']=$arrLicense['text'];
                $list[$key]['licenseImg']=$arrLicense['img'];

                $arrWater = $this->JsonDataProcessing($list[$key]['water']);
                $list[$key]['waterText']=$arrLicense['text'];
                $list[$key]['waterImg']=$arrWater['img'];

        }
        import("ORG.Util.Page");// 导入分页类
        $Page = getpage($count,$num);
        if(LANG_SET != 'zh-cn'){
            $Page->setConfig('header','Total&nbsp;&nbsp;'.$count.'&nbsp;&nbsp;Record');
            $Page->setConfig('first','first');
            $Page->setConfig('prev','<<');
            $Page->setConfig('next','>>');
            $Page->setConfig('last','last');
        }
        $show       = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('list',$list);
        $this->assign('userList',$userList);
	    //print_r($list);
        $this->display();
    }
    
}
